"use strict";
exports.__esModule = true;
var path = require("path");
var fse = require("fs-extra");
var config = require("./store.config.js");
var albumPath = path.resolve(__dirname, "..", config.album.contentDir);
var deployPath = path.resolve(
    __dirname,
    "../../../",
    config.generate.deploy.outpath
  );
var content = {
    config: config,
    data: []
};

fse.ensureDirSync(deployPath);
fse.ensureFileSync(path.resolve(deployPath, config.generate.filename));
fse.readdirSync(albumPath, "utf8").forEach(function (dir) {
    var stat = fse.statSync(path.resolve(albumPath, dir));
    if (stat.isDirectory()) {
        var content_1 = fse.readdirSync(path.resolve(albumPath, dir), "utf8");
        content_1.forEach(function (file) {
            if (config.generate.deploy.useTimeStamp) {
                if (file !== config.album.configFile &&
                    file !== config.album.defaultHover &&
                    Number.isNaN(Number(file))) {
                    fse.renameSync(path.resolve(albumPath, dir, file), path.resolve(albumPath, dir, new Date().getTime().toString()));
                }
            }
        });
    }
});
fse.readdirSync(albumPath, "utf8").forEach(function (dir, k) {
    var stat = fse.statSync(path.resolve(albumPath, dir));
    if (stat.isDirectory()) {
        var dirContent = fse
            .readdirSync(path.resolve(albumPath, dir), "utf8")
            .filter(function (v) {
            return v !== config.album.configFile && v !== config.album.defaultHover;
        });
        var albumConfig = require(path.resolve(albumPath, dir, config.album.configFile));
        content.data.push({
            id: k,
            name: dir,
            content: dirContent.sort(),
            config: albumConfig
        });
    }
});
fse.writeJSON(path.resolve(albumPath, config.generate.filename), content);
fse.writeJSON(path.resolve(deployPath, config.generate.filename), content);